{extend name="common/base" /}
{block name="content"}
    <div class="iframe_div layui-anim layui-anim-upbit">
        <form class="layui-form layui-form-pane" action="" lay-filter="op_form">


            <div class="layui-form-item">
                <label class="layui-form-label">账号</label>
                <div class="layui-input-block">
                    <input type="text" name="username" disabled id="username" value="{$user.username}" autocomplete="off" placeholder="账号" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">昵称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" value="{$user.name}" autocomplete="off" placeholder="昵称" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">当前密码</label>
                <div class="layui-input-block">
                    <input type="password" name="old_password" id="old_password" autocomplete="off" placeholder="当前密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" id="password" autocomplete="off" placeholder="新密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">重复新密码</label>
                <div class="layui-input-block">
                    <input type="password" name="re_password" id="re_password" autocomplete="off" placeholder="重复新密码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit="" lay-filter="save_sub">修改</button>
                </div>
            </div>
        </form>
    </div>
{/block}
{block name="script"}
<script>
    layui.config({
        base: '<?php echo SITE;?>static/layuiadmin/'
    }).extend({
        index: 'lib/index'
    }).use(['index'],async () => {
        const { layer,form, admin, table, $,element } = layui;

        /*监听提交*/
        form.on('submit(save_sub)', function(data){
            data =data.field;
            let type = 'PUT';
            let url = '/admin/user/{$user.id}';

            if(data.password !== data.re_password){
                layer.msg('两次密码不一样');
                return false;
            }

            $.ajax({
                type: type,
                url: url,
                data: data,
                datatype: 'json',
                success: function (res) {
                    if (res.status) {
                        layer.closeAll();
                    }
                    layer.msg(res.msg);
                }
            });
            return false;
        });

    });
</script>
{/block}


{block name="template"}
{/block}